home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / asm / alib11b.zip / CODE1.ZIP / DEBUG / KEYBREAK.ASM next >
Assembly Source File  |  1994-10-03  |  5KB  |  106 lines

  1. ; This code creates a debug abort key which will transfer control
  2. ; back to most debug programs.  Hitting the '5' key forces an
  3. ; int 3 (debug breakpoint).
  4. ;
  5. ; By Garrett P. Nievin
  6. ;
  7. ; To add a hardware breakout switch just put a switch between
  8. ; pins 17 (NMI) and 40 (+5V) on your 8088 chip, and a switch between
  9. ; pins 21 (RESET) and 40 will do a system reset/reboot.)
  10. ;
  11. ; This is a .COM program
  12.  
  13. code    segment para public 'code'
  14.         assume cs:code,ds:nothing,es:nothing
  15.         org     0100h
  16.  
  17. hotkey  equ     4ch         ; scan code for hot key = "5" on keypad
  18. portA   equ     60h         ; 8255A port A, usually keybd scan code
  19. portB   equ     61h         ; 8255A port B, various switches
  20. release equ     80h         ; hi bit in scan code means key release
  21. hibiton equ     80h         ; hi bit in byte for or'ing in
  22. hbitoff equ     7fh         ; hi bit in byte for and'ing out
  23.  
  24. start   proc    far
  25. begcode:
  26.     jmp  implant            ; jump around interrupt handler code
  27. begres:                     ; area to remain core resident
  28.  
  29. rescode  proc               ; keystroke causes jump to here
  30.     jmp  over               ; jump over memory signature
  31.     db  'bcGN'              ; program signature in memory
  32. over:                       ;
  33.     sti                     ; allow interrupts
  34.     push ax                 ; save that register
  35.     in   al,portA           ; get keyboard scan code
  36.     cmp  al,hotkey          ; hotkey?
  37.     jne  normal             ; yes, go hanlit
  38.     push dx                 ; save register
  39.     mov  dx,0020h           ; port 20h = PIC port to send EOI to
  40.     mov  al,dl              ; 20h turns on EOI bit
  41.     out  dx,al              ; tell interrupt controller we be done
  42.     pop  dx                 ; restore register
  43.     in   al,portB           ; get portB
  44.     or   al,hibiton         ; set acknowledge / clear keyboard bit
  45.     out  portB,al           ; and out it again
  46.     and  al,hbitoff         ; clear ack bit
  47.     out  portB,al           ; out that, enabling keyboard again
  48.     pop  ax                 ; restore original register
  49.     int  3                  ;
  50.     iret                    ;
  51.  
  52. normal:                     ;
  53.     pop  ax                 ; restore that register
  54.     jmp  dword ptr cs:oldint9    ; goto old int9 handler
  55. oldint9  dw  0,0            ; doubleword value of old int9 vector
  56. rescode  endp
  57.  
  58. endres:                     ; end of core res area
  59.  
  60. reslen  equ endres - begres           ; length of new resident code
  61. strtres equ begres - begcode + 100h   ; start of resident code
  62. psplen  equ 5ch                       ; length of necessary PSP
  63.  
  64. implant:                    ; code to put new int 9 front end in core
  65.     mov  ax,3509h           ; get int vector function
  66.     int  21h                ; get vector of interrupt 9 handler
  67.     cmp  es:[bx+3],'cb'     ; already loaded?
  68.     jne  fresh              ; nope, go install
  69.     cmp  es:[bx+5],'NG'     ; make sure
  70.     jne  fresh              ; naaah, go install
  71.     lea  dx,cs:stalemsg     ; DX points to already installed message
  72.     mov  ah,09h             ; DOS display string func
  73.     int  21h                ; go display message
  74.     mov  ax,4cffh           ; terminate with code = 0xff
  75.     int  21h                ;
  76.         
  77. fresh:
  78.     lea  dx,cs:instlmsg     ; DX points to installation message
  79.     mov  ah,09h             ; display string function
  80.     int  21h                ; give the user the poop
  81.     mov  ax,3509h           ; get int vector function
  82.     int  21h                ; get vector of old interrupt 9 handler
  83.     mov  oldint9,bx         ; int location in ES:BX, save it
  84.     mov  oldint9+2,es       ; "
  85.     mov  ax,2509h           ; set new interrupt 9 vector to me
  86.     mov  dx,offset rescode  ; address of which is in DX
  87.     int  21h                ; go do it
  88.     push cs                 ; DS and ES both end
  89.     pop  es                 ; up pointing at
  90.     push cs                 ; code area
  91.     pop  ds                 ; "
  92.     mov  di,psplen          ; where program will end up
  93.     mov  si,strtres         ; start of resident code
  94.     mov  cx,reslen          ; amount of resident code to move
  95.     cld                     ; go forward in move
  96.     rep  movsb              ; move code back in mem
  97.     mov  dx,psplen + reslen ; DX pointing to next free paragraph
  98.     mov  ax,3100h           ; keep, return code of 0
  99.     int  21h                ; terminate
  100. stalemsg db 'Bugout already resident.',10,13,7,'$'
  101. instlmsg db 'Bugout loaded and active, keypad-5 is break key.',10,13,'$'
  102. start    endp
  103. code     ends
  104.     end  start
  105.